/*
 * @Author: your name
 * @Date: 2020-08-19 11:16:54
 * @LastEditTime: 2021-01-13 10:07:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wms2\src\main.js
 */
import 'babel-polyfill'
import Vue from 'vue'

import Cookies from 'js-cookie'
import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import Element from 'element-ui'
import { Loading } from 'element-ui'
Vue.use(Loading)
import './styles/element-variables.scss'
import '@/styles/index.scss' // global css
import App from './App'
import store from './store'
import router from './router'
import i18n from './lang' // internationalization
import langZH from '@/lang/zh.js'
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
import './plugins/vxe-table'
import Print from 'vue-print-nb'
import { getToken } from '@/utils/auth'
import getEnumsOrDict from '@/utils/stateInvariant.js'
Vue.prototype.getEnumsOrDict = getEnumsOrDict
Vue.use(Print)
import * as filters from './filters' // global filters
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
/* import { mockXHR } from '../mock'
if (process.env.NODE_ENV === 'production') {
  mockXHR()
} */
Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})

import VueAMap from 'vue-amap'
VueAMap.initAMapApiLoader({
  key: '73036b3be3046970706c703017d1f500',
  plugin: [
    'AMap.Autocomplete',
    'AMap.PlaceSearch',
    'AMap.Scale',
    'AMap.OverView',
    'AMap.ToolBar',
    'AMap.MapType',
    'AMap.PolyEditor',
    'AMap.CircleEditor',
    'AMap.Geocoder'
  ],
  v: '1.4.4',
  uiVersion: '1.0'
})
Vue.use(VueAMap)
Vue.prototype.openLoading = function(config, time = 15000) {
  const defaultConfig = {
    text: '努力加载中...',
    duration: 15000
  }
  if (Object.prototype.toString.call(config) === '[object Object]') {
    Object.assign(defaultConfig, config)
  } else {
    defaultConfig.text = config
    defaultConfig.duration = time
  }
  const loading = this.$loading({ // 声明一个loading对象
    lock: true, // 是否锁屏
    text: defaultConfig.text, // 加载动画的文字
    spinner: 'el-icon-loading', // 引入的loading图标
    background: 'rgba(0, 0, 0, 0.8)', // 背景颜色
    target: '.sub-main', // 需要遮罩的区域
    body: true,
    customClass: 'mask' // 遮罩层新增类名
  })
  const duration = defaultConfig.duration
  if (Number(duration)) {
    setTimeout(function() {
      loading.close()
    }, duration)
  }
  return loading
}
// 引入echarts
import echarts from 'echarts'
import 'echarts/map/js/china'

Vue.prototype.$echarts = echarts
Vue.prototype.$eventBus = new Vue()

const base_url = process.env.NODE_ENV === 'development' ? window.BaseUrl.devUrl : window.BaseUrl.ApiUrl
Vue.prototype.BASE_API_URL = base_url
Vue.prototype.uploadUrl = `${base_url}arpa-basic-api/fileUpload`
Vue.prototype.getAuthorization = function() {
  return { Authorization: 'Bearer ' + getToken() }
}
// 修改国际化标题，Tags-View
Vue.prototype.modifyTitle = langZH.modifyTitle.bind(langZH)
